/**
 * Created by DELL on 2017/6/23.
 */
var settings = {
    "sAjaxSource": window.globalHost + common.creditRuleListPath,
    "aoColumns": [{
        "mDataProp": function(obj) {
            return (obj.updateTime?obj.updateTime:"无信息");
        },
        "sTitle": "修改时间",
        "sDefaultContent": "",
        "sClass": "center"
    },{
        "mDataProp": function(obj) {
            // return (!!obj.villageName?obj.villageName:"无信息")+'<br>'+(obj.houseAddress?obj.houseAddress:"无信息");
            return '<a href="javascript:;" class="ruleName" data-id="'+obj.id+'" data-maxPoint="'+obj.maxPoint+'" ' +
                'data-minPoint="'+obj.minPoint+'" data-ruleType="'+obj.ruleType+'">'+(obj.ruleName?obj.ruleName:"无信息")+'</a>'
        },
        "sTitle": "规则名称",
        "sDefaultContent": ""
    }, {
        "mDataProp": function (obj) {
            return (!!obj.minPoint?obj.minPoint:"无信息")+'&nbsp; --- &nbsp;'+(obj.maxPoint?obj.maxPoint:"无信息");
        },
        "sTitle": "积分数值",
        "sDefaultContent": ""
    }],
    "fnServerParams": function(aoData) {
        return common.getSearchData("form.data-list-search",aoData);
    }
};
var options = $.extend(true, {}, _dataTableSettings, settings);
/**
 * 实例化 中介联系人 列表插件
 * @type {[type]}
 */
var $currentDataTable=$("#data-list");
var oTable = $currentDataTable.dataTable(options);
searchList.getDataList(oTable);
searchList.resetSearch(oTable);

$currentDataTable.off("click",".ruleName").on("click",".ruleName",function (e) {
    var $this=$(this);
    var selfId=$this.attr("data-id");
    var selfRuleName=$this.html();
    var selfMinPoint=$this.attr("data-minPoint");
    var selfMaxPoint=$this.attr("data-maxPoint");
    var sendData={};
    var content='<div style="width: 100%;overflow:hidden;" id="update-rule">' +
        '<input type="hidden" name="id" value="'+selfId+'"> ' +
        '<div class="form-group clearfix" style="margin-top:30px;">' +
            '<label class="col-sm-offset-1 col-sm-2 control-label text-center">规则名称</label><p class="col-sm-8" style="margin:0;line-height: 34px;font-size:16px;font-weight:bold;">'+(selfRuleName?selfRuleName:"")+'</p>'+
        '</div>' +
        '<div class="form-group clearfix" style="">' +
            '<label class="col-sm-offset-1 col-sm-2 control-label text-center">积分数值</label>' +
            '<input class="col-sm-2" type="number" name="minPoint" value="'+(selfMinPoint!="undefined"?selfMinPoint:"")+'">' +
            '<label class="col-sm-4 control-label text-center">至</label>' +
            '<input class="col-sm-2" type="number" name="maxPoint" value="'+(selfMaxPoint!="undefined"?selfMaxPoint:"")+'">' +
        '</div>' +
        '</div>';
    common.openTempDialog({
        type: 1,
        title: '配置规则',
        area: ['800px', '300px'],
        content: content,
        FailedMsg: "请输入完善配置信息",
        sendData: sendData,
        ajaxUrl: window.globalHost+common.creditRuleUpdatePath,
        contentOnLoad: function (layerDocument) {
            // 弹窗内控件加载初始化
            var content = layerDocument.find("#update-rule");
        },
        beforeSend: function (layerDocument) {
            var content = layerDocument.find("#update-rule");
            sendData.id=selfId;
            // sendData.ruleName=content.find("input[name='ruleName']").val();
            sendData.minPoint=content.find("input[name='minPoint']").val();
            sendData.maxPoint=content.find("input[name='maxPoint']").val();
            return sendData.id && sendData.minPoint && sendData.maxPoint;
        },
        resOk: function () {
            //如果更新成功，刷新表格数据
            oTable.fnClearTable();
        }
    });
});